//
//  EFengShareController.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/2/29.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengShareController.h"
#import "UIBarButtonItem+category.h"
#import "EFengShareButton.h"
#import "EFengShareCell.h"
#import "EFengShare.h"
#import "EFengComposeController.h"
#import "CXmppRequestMgr.h"
#import "UIUtil.h"
#import "EFengShareFrame.h"
#import "EFengContent.h"
#import "EFengShareDel.h"
#import "EFengShareCommentDel.h"
#import "CContactMgr.h"
#import "CFolderMgr.h"
#import "CContactModel.h"
#import "UIUtil.h"
#import "CShareMgr.h"
#import "CShareCommentMgr.h"
#import "MBProgressHUD+WZ.h"
#import "MJExtension.h"
#import "UIUtil.h"
#import "CAttentionMgr.h"
#import "CMineAttentionContact.h"
#import "EFengShareCommentToolBar.h"
#import "EFengShareEmotionView.h"
#import "MJRefresh.h"
#import "RIButtonItem.h"
#import "UIActionSheet+Blocks.h"
#import "CShareCommentDelMgr.h"
#import "CShareDelMgr.h"
#import "EFengPersonalShareController.h"
#import "EFengMineShareController.h"
#import "UIImageView+WebCache.h"
#import "EFengShareNewCommentController.h"
#import "CXmppMgr.h"
#import "CUserSettingMgr.h"
#import "CUserSettingModel.h"
#import "CSharePersonMgr.h"
#import "JKAlertDialog.h"
#import "MBProgressHUD+WZ.h"
static const void * const EFengShareDispatchQueueSpecificKey = &EFengShareDispatchQueueSpecificKey;

@interface EFengShareController ()<UITableViewDataSource, UITableViewDelegate, EFengShareCellDelegate, EFengShareCommentToolBarDelegate>

{
    dispatch_queue_t _efengShareQueen;
}
StrongProperty NSMutableArray *dataArray;
StrongProperty NSMutableArray *shareDataArray;

StrongProperty NSMutableArray *attentionShareDataArray;
StrongProperty NSMutableArray *attentionDataArray;

StrongProperty UITableView *tableView;

StrongProperty CContactModel *curContact;
StrongProperty CContactMgr *conMgr;

StrongProperty CShareMgr *shareMgr;
StrongProperty CShareCommentMgr *commentMgr;
StrongProperty CShareCommentDelMgr *shareCommentDelMgr;
StrongProperty CShareDelMgr *shareDelMgr;
StrongProperty CAttentionMgr *attenMgr;
StrongProperty CSharePersonMgr *personMgr;

StrongProperty EFengContent *selectedComment;
StrongProperty EFengShare *selectedShare;
StrongProperty EFengShare *maxShare;
StrongProperty EFengShare *minShare;

StrongProperty EFengShare *maxAttentionShare;
StrongProperty EFengShare *minAttentionShare;

AssignProperty NSInteger allUnreadCommentCount;
StrongProperty EFengContent *lastUnReadComment;
//AssignProperty NSInteger currentRow;
StrongProperty CUserSettingModel *settingModel;
StrongProperty CUserSettingMgr *settingMgr;
WeakProperty UILabel *noticeLabel;
StrongProperty UIView *topView;
@end

@implementation EFengShareController

#pragma mark 懒加载

- (CContactModel *)curContact
{
    if (_curContact == nil) {
        _curContact = [self.conMgr loadCurContact];
    }
    return _curContact;
}


- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (NSMutableArray *)shareDataArray
{
    if (_shareDataArray == nil) {
        _shareDataArray = [NSMutableArray array];
    }
    return _shareDataArray;
}

- (NSMutableArray *)attentionDataArray
{
    if (_attentionDataArray == nil) {
        _attentionDataArray = [NSMutableArray array];
    }
    return _attentionDataArray;
}

- (NSMutableArray *)attentionShareDataArray
{
    if (_attentionShareDataArray == nil) {
        _attentionShareDataArray = [NSMutableArray array];
    }
    return _attentionShareDataArray;
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:K_XMPPDelComment object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:K_XMPPReceiveComment object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:K_XMPPDelShare object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:IMDIDUPDATEMINEATTENTION object:nil];
}
- (void)addtapToStatusBar
{
    _topView = [[UIView alloc] init];
    _topView.frame = [UIApplication sharedApplication].statusBarFrame;
    _topView.backgroundColor = [UIColor clearColor];
    [_topView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topViewClick)]];
    [[UIApplication sharedApplication].keyWindow addSubview:_topView];
}
-(void)topViewClick
{
    __weak typeof (self) weakself = self;
    [UIView animateWithDuration:0.5f animations:^{
        weakself.tableView.contentOffset = CGPointMake(0, 0);
    }];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = CommonColor;
//    self.currentRow = 0 ;
    //分享队列
    _efengShareQueen = dispatch_queue_create([[NSString stringWithFormat:@"efengShare.%@", self] UTF8String], NULL);
    dispatch_queue_set_specific(_efengShareQueen, EFengShareDispatchQueueSpecificKey, (__bridge void *)self, NULL);
    
    
    [self.navigationController setNavigationBarHidden:NO];
    [self.navigationItem setHidesBackButton:YES];
    self.navigationItem.title = @"分享";
     self.navigationItem.rightBarButtonItem = [UIBarButtonItem BarButtonItemWithImageName:@"btn-more" title:nil target:self sel:@selector(releaseShare) titleFont:Font18 titleColor:WhiteColor];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleComment) name:K_XMPPReceiveComment object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleComment) name:K_XMPPDelComment object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleShare:) name:K_XMPPDelShare object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUpdateMineAttention) name:IMDIDUPDATEMINEATTENTION object:nil];
    
    self.shareMgr = [[CShareMgr alloc] init];
    self.commentMgr = [[CShareCommentMgr alloc] init];
    self.conMgr = [[CContactMgr alloc] init];
    self.attenMgr = [[CAttentionMgr alloc] init];
    self.shareCommentDelMgr = [[CShareCommentDelMgr alloc] init];
    self.shareDelMgr = [[CShareDelMgr alloc] init];
    self.settingMgr = [[CUserSettingMgr alloc] init];
    self.personMgr = [[CSharePersonMgr alloc] init];
    
    self.curContact = [self.conMgr loadCurContact];
    self.settingModel = [self.settingMgr getUserSetting];
    
    self.tableView.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, HARDWARE_SCREEN_HEIGHT - 64.0f);
    [self.view addSubview:self.tableView];
    
    
    //增加下拉刷新
    
    __block EFengShareController *weakSelf = self;
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf loadNewData];
    }];
    [header setTitle:@"加载中..." forState:MJRefreshStateRefreshing];
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = NO;
    self.tableView.header = header;
    //增加上拉加载更多
    
    MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        
        [weakSelf loadMoreData];
    }];
    [footer setTitle:@"正在加载..." forState:MJRefreshStateRefreshing];
    
    
    self.tableView.footer = footer;

    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
    [self.view addGestureRecognizer:tap];
    
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = ClearColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = Font16;
    label.textColor = RGBCOLORWITH16COLOR(0xb1b1b1);
    label.text = @"这里暂时空空的～";
    label.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, Font16.lineHeight);
    label.center = self.view.center;
    [self.view addSubview:label];
    self.noticeLabel = label;
    self.noticeLabel.hidden = YES;
}

- (void)handleShare:(NSNotification *)notice
{
    dispatch_block_t ablock = ^{
        NSArray *shareIdArray = notice.object;
        for (NSString *shareId in shareIdArray) {
            __block EFengShare *share = nil;
            [self.attentionShareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                if ([obj.shareId isEqualToString:shareId]) {
                    share = obj;
                    *stop = YES;
                }
            }];
            [self.attentionShareDataArray removeObject:share];
        }

        self.maxAttentionShare = self.attentionShareDataArray.firstObject;
        self.minAttentionShare = self.attentionShareDataArray.lastObject;
        
        
        for (NSString *shareId in shareIdArray) {
            __block EFengShare *share = nil;
            [self.shareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                if ([obj.shareId isEqualToString:shareId]) {
                    share = obj;
                    *stop = YES;
                }
            }];
            [self.shareDataArray removeObject:share];
        }
        
        self.maxShare = self.shareDataArray.firstObject;
        self.minShare = self.shareDataArray.lastObject;
        
        NSMutableArray *arrayM1 = [NSMutableArray array];
        if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
            
            //        [self.attentionDataArray removeAllObjects];
            [self.attentionShareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
                
                obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
                obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
                obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
                if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                    obj.isShowShanchu = YES;
                } else {
                    obj.isShowShanchu = NO;
                }
                
                shareF.share = obj;
                [arrayM1 addObject:shareF];
            }];
            //        [self.tableView reloadData];
            
        } else {
            
            //        [self.dataArray removeAllObjects];
            
            [self.shareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
                obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
                obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
                obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
                if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                    obj.isShowShanchu = YES;
                } else {
                    obj.isShowShanchu = NO;
                }
                
                shareF.share = obj;
                [arrayM1 addObject:shareF];
            }];
            //        [self.tableView reloadData];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
                self.attentionDataArray = [arrayM1 mutableCopy];
                if (self.attentionShareDataArray.count == 0) {
                    self.noticeLabel.hidden = NO;
                }
                else
                {
                    self.noticeLabel.hidden = YES;
                }
                
            } else {
                if (self.shareDataArray.count == 0) {
                    self.noticeLabel.hidden = NO;
                }
                else
                {
                    self.noticeLabel.hidden = YES;
                }
                
                self.dataArray = [arrayM1 mutableCopy];
            }
        
        [self.tableView reloadData];
        });
    };
    if (dispatch_get_specific(EFengShareDispatchQueueSpecificKey)) {
        ablock();
    } else {
        dispatch_async(_efengShareQueen, ablock);
    }

}

- (void)WZAttributedActionDidClickForShowPersonalShare:(NSNotification *)notice
{
    [[EFengShareCommentToolBar defaultShareCommentToolBar] resetToolPositionToInitial];
    self.tabBarController.tabBar.hidden = NO;
    
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    nav.navigationBarHidden = NO;
    self.navigationController.navigationBarHidden = YES;
    
    EFengPersonalShareController *per = [[EFengPersonalShareController alloc] init];
    per.userId = notice.object;
    
    [nav pushViewController:per animated:YES];

}

- (void)handleShareDataWithArray:(NSArray *)array
{
    dispatch_block_t ablock = ^{
        __block NSMutableArray *arrayM = [NSMutableArray array];
        __block NSMutableArray *arrayM1 = [NSMutableArray array];
        [self.shareMgr batchUpdateAllUnreadShareToReadShareWithShareList:array];
        
        
        if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
            if (array.count > 0) {
                [array enumerateObjectsUsingBlock:^(EFengShare  *obj, NSUInteger idx, BOOL *stop) {
                    EFengShare *hasShare = nil;
                    for (EFengShare *share in self.attentionShareDataArray) {
                        if ([share.shareId isEqualToString:obj.shareId]) {
                            hasShare = share;
                        }
                    }
                    if (hasShare) {
                        [self.attentionShareDataArray removeObject:hasShare];
                    }
                    
                }];
                [arrayM addObjectsFromArray:array];
            }
            [arrayM addObjectsFromArray:self.attentionShareDataArray];
            NSArray *sortArray = [arrayM sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO]]];
            [self.attentionShareDataArray removeAllObjects];
            [self.attentionShareDataArray addObjectsFromArray:sortArray];
            self.maxAttentionShare = self.attentionShareDataArray.firstObject;
            self.minAttentionShare = self.attentionShareDataArray.lastObject;
            
//            [self.attentionDataArray removeAllObjects];
            [self.attentionShareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
                obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
                obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
                
                obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
                if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                    obj.isShowShanchu = YES;
                } else {
                    obj.isShowShanchu = NO;
                }
                
                shareF.share = obj;
                [arrayM1 addObject:shareF];
            }];
        } else {
            if (array.count > 0) {
                [array enumerateObjectsUsingBlock:^(EFengShare  *obj, NSUInteger idx, BOOL *stop) {
                    EFengShare *hasShare = nil;
                    for (EFengShare *share in self.shareDataArray) {
                        if ([share.shareId isEqualToString:obj.shareId]) {
                            hasShare = share;
                        }
                    }
                    if (hasShare) {
                        [self.shareDataArray removeObject:hasShare];
                    }
                    
                }];
                [arrayM addObjectsFromArray:array];
            }
            [arrayM addObjectsFromArray:self.shareDataArray];
            NSArray *sortArray = [arrayM sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO]]];
            [self.shareDataArray removeAllObjects];
            [self.shareDataArray addObjectsFromArray:sortArray];
            self.maxShare = self.shareDataArray.firstObject;
            self.minShare = self.shareDataArray.lastObject;
            
//            [self.dataArray removeAllObjects];
            [self.shareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
                obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
                obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
                
                obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
                if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                    obj.isShowShanchu = YES;
                } else {
                    obj.isShowShanchu = NO;
                }
                
                shareF.share = obj;
                [arrayM1 addObject:shareF];
            }];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
                self.attentionDataArray = [arrayM1 mutableCopy];
                if (self.attentionShareDataArray.count == 0) {
                    self.noticeLabel.hidden = NO;
                }
                else
                {
                    self.noticeLabel.hidden = YES;
                }
                
            } else {
                if (self.shareDataArray.count == 0) {
                    self.noticeLabel.hidden = NO;
                }
                else
                {
                    self.noticeLabel.hidden = YES;
                }
                
                self.dataArray = [arrayM1 mutableCopy];
            }
            [self.tableView.header endRefreshing];
            [self.tableView.footer endRefreshing];
            [self.tableView reloadData];
            [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPReceiveShare object:nil];
        });
    };
    
    if (dispatch_get_specific(EFengShareDispatchQueueSpecificKey)) {
        ablock();
    } else {
        dispatch_async(_efengShareQueen, ablock);
    }
    
}

- (void)handleComment
{
    if (self.curContact == nil) {
        return;
    }
    dispatch_block_t ablock = ^{
        
        __block NSMutableArray *arrayM1 = [NSMutableArray array];
        if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
            self.allUnreadCommentCount = [self.commentMgr getShareCommentAllUnReadCount];
            self.lastUnReadComment = [self.commentMgr getMaxUnreadShareComment];
            [self.commentMgr updateUnAttentionCommentUnReadToRead];
//            [self.attentionDataArray removeAllObjects];
            [self.attentionShareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
                
                obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
                obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
                obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
                if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                    obj.isShowShanchu = YES;
                } else {
                    obj.isShowShanchu = NO;
                }
                
                shareF.share = obj;
                [arrayM1 addObject:shareF];
            }];
            
        } else {
            self.allUnreadCommentCount = [self.commentMgr getShareCommentAllUnReadCount];
            self.lastUnReadComment = [self.commentMgr getMaxUnreadShareComment];
            [self.commentMgr updateUnAttentionCommentUnReadToRead];
//            [self.dataArray removeAllObjects];
            [self.shareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
                EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
                
                obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
                obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
                obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
                if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                    obj.isShowShanchu = YES;
                } else {
                    obj.isShowShanchu = NO;
                }
                
                shareF.share = obj;
                [arrayM1 addObject:shareF];
            }];
        }

        
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
                self.attentionDataArray = [arrayM1 mutableCopy];
                if (self.attentionShareDataArray.count == 0) {
                    self.noticeLabel.hidden = NO;
                }
                else
                {
                    self.noticeLabel.hidden = YES;
                }

            } else {
                if (self.shareDataArray.count == 0) {
                    self.noticeLabel.hidden = NO;
                }
                else
                {
                    self.noticeLabel.hidden = YES;
                }

                self.dataArray = [arrayM1 mutableCopy];
            }
           
            [self.tableView reloadData];
        });
    };

        
    
    if (dispatch_get_specific(EFengShareDispatchQueueSpecificKey)) {
        ablock();
    } else {
        dispatch_async(_efengShareQueen, ablock);
    }
}

- (void)releaseShare
{
    
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    nav.navigationBarHidden = NO;
    self.navigationController.navigationBarHidden = YES;
    
    EFengComposeController *compose = [[EFengComposeController alloc] init];
    [nav pushViewController:compose animated:YES];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    
    if (IsIOS7) {
        [self.navigationController.navigationBar setBarTintColor:RGBCOLOR(44, 170, 253)];
    } else {
        [self.navigationController.navigationBar setTintColor:RGBCOLOR(44, 170, 253)];
    }
    
    self.tableView.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, HARDWARE_SCREEN_HEIGHT - 64.0f);
    
    EFengShareCommentToolBar *tool = [EFengShareCommentToolBar defaultShareCommentToolBar];
    
    tool.eFengShareCommentToolBarDelegate = self;
    CGRect fr = tool.frame;
    fr.origin.y = HARDWARE_SCREEN_HEIGHT - 64.0f;
    tool.frame = fr;
    [self.view addSubview:tool];

    
    EFengShareEmotionView *emo = [EFengShareEmotionView defaultShareEmotionView];
    [self.view addSubview:emo];
    
    self.settingModel = [self.settingMgr getUserSetting];
    [self loadNewData];
    [self handleComment];
    [self addtapToStatusBar];
    }

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WZAttributedActionDidClickForShowPersonalShare:) name:WZAttributedActionDidClick object:nil];
}


- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    EFengShareCommentToolBar *tool = [EFengShareCommentToolBar defaultShareCommentToolBar];
    tool.eFengShareCommentToolBarDelegate = nil;
    [tool removeFromSuperview];
    [_topView removeFromSuperview];
    [[EFengShareEmotionView defaultShareEmotionView] removeFromSuperview];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:WZAttributedActionDidClick object:nil];
}


- (void)handleUpdateMineAttention
{
    [self.attentionShareDataArray removeAllObjects];
    self.maxAttentionShare = nil;
    self.minAttentionShare = nil;
    [self loadNewData];
}


- (void)loadNewData
{
    if (self.curContact == nil) {
        [self.tableView.header endRefreshing];
        return;
    }
    if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
        NSString *date1 = [self.shareMgr getMaxDateShare];
        NSString *curDate = [UIUtil getCurrentTimeStamp];
        if (!M_ISSTRNULL(date1)) {
            
        } else {
            date1 = curDate;
            //         date1 = @"1456816235900";
            EFengShare *share = [[EFengShare alloc] init];
            share.isLocal = YES;
            share.shareId = [NSString stringWithFormat:@"isLocal%@",date1];
            share.date = date1;
            [self.shareMgr insertWithShare:share];
        }
        
        NSString *date3 = [self.commentMgr getMaxDateShareComment];
        if (!M_ISSTRNULL(date3)) {
            
        } else {
            date3 = curDate;
            //        date3 = @"1456816235900";
            EFengContent *comment = [[EFengContent alloc] init];
            comment.isLocal = YES;
            comment.shareId = [NSString stringWithFormat:@"isLocal%@",date3];
            comment.date = date3;
            [self.commentMgr insertWithShareComment:comment];
        }
        
        [[CXmppRequestMgr shareInstance] getShareCommentListWithDate:date3 shareDate:date1 userId:self.curContact.UserID releaseUserId:@"" findType:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            //         NSLog(@"3333");
            
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                NSArray *array = responseObject[@"text"];
                NSArray *commentArray = [EFengContent objectArrayWithKeyValuesArray:array];
                [self.commentMgr batchInsertWithCommentList:commentArray];
                
            }
            
            [self handleComment];
            
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            [self handleComment];
        }];
        [[CXmppRequestMgr shareInstance] getShareListWithDate:date1 findType:@"" userId:self.curContact.UserID releaseUserId:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                NSArray *array1 = responseObject[@"text"];
                NSArray *shareArray = [EFengShare objectArrayWithKeyValuesArray:array1];
                [self.shareMgr batchInsertWithShareList:shareArray];
                [self.personMgr batchInsertWithShareList:shareArray];
            }
            [self handleShareDataWithArray:[self.shareMgr getAttentionNewerShareWithMaxTimeStamp:self.maxAttentionShare.date curUserId:self.curContact.UserID]];
        
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            [self handleShareDataWithArray:[self.shareMgr getAttentionNewerShareWithMaxTimeStamp:self.maxAttentionShare.date curUserId:self.curContact.UserID]];
        }];
    }
    else{
    //查看所有人
    NSString *date1 = [self.shareMgr getMaxDateShare];
    NSString *curDate = [UIUtil getCurrentTimeStamp];
    if (!M_ISSTRNULL(date1)) {
        
    } else {
        date1 = curDate;
        //         date1 = @"1456816235900";
        EFengShare *share = [[EFengShare alloc] init];
        share.isLocal = YES;
        share.shareId = [NSString stringWithFormat:@"isLocal%@",date1];
        share.date = date1;
        [self.shareMgr insertWithShare:share];
    }
    
    NSString *date3 = [self.commentMgr getMaxDateShareComment];
    if (!M_ISSTRNULL(date3)) {
        
    } else {
        date3 = curDate;
        //        date3 = @"1456816235900";
        EFengContent *comment = [[EFengContent alloc] init];
        comment.isLocal = YES;
        comment.shareId = [NSString stringWithFormat:@"isLocal%@",date3];
        comment.date = date3;
        [self.commentMgr insertWithShareComment:comment];
    }
    
    [[CXmppRequestMgr shareInstance] getShareCommentListWithDate:date3 shareDate:date1 userId:self.curContact.UserID releaseUserId:@"" findType:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
        //         NSLog(@"3333");
        
        if ([responseObject[@"result"] isEqualToString:@"success"]) {
            NSArray *array = responseObject[@"text"];
            NSArray *commentArray = [EFengContent objectArrayWithKeyValuesArray:array];
            [self.commentMgr batchInsertWithCommentList:commentArray];
        }
        [self handleComment];
        
        
    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self handleComment];
    }];
    
    
    
    [[CXmppRequestMgr shareInstance] getShareListWithDate:date1 findType:@"" userId:self.curContact.UserID releaseUserId:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        if ([responseObject[@"result"] isEqualToString:@"success"]) {
            NSArray *array1 = responseObject[@"text"];
            NSArray *shareArray = [EFengShare objectArrayWithKeyValuesArray:array1];
            [self.shareMgr batchInsertWithShareList:shareArray];
            [self.personMgr batchInsertWithShareList:shareArray];
        }
        
        [self handleShareDataWithArray:[self.shareMgr getNewerShareWithMaxTimeStamp:self.maxShare.date]];
        
    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self handleShareDataWithArray:[self.shareMgr getNewerShareWithMaxTimeStamp:self.maxShare.date]];
    }];
}
}

- (void)loadMoreData
{
    if (self.curContact == nil) {
        [self.tableView.footer endRefreshing];
    }
    
    if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
        
        NSArray *array = nil;
        if (self.maxAttentionShare == nil || self.minAttentionShare == nil) {
            [self.tableView.footer endRefreshing];
            [self.tableView reloadData];
        } else {
            array = [self.shareMgr getAttentionOlderShareWithMinTimeStamp:self.minAttentionShare.date curUserId:self.curContact.UserID];
            if (array.count > 0) {
                
                [self handleShareDataWithArray:array];
                
            } else {
                NSString *date1 = [self.shareMgr getMinDateShare];
                NSString *curDate = [UIUtil getCurrentTimeStamp];
                if (!M_ISSTRNULL(date1)) {
                    
                } else {
                    date1 = curDate;
                    //         date1 = @"1456816235900";
                    EFengShare *share = [[EFengShare alloc] init];
                    share.isLocal = YES;
                    share.shareId = [NSString stringWithFormat:@"isLocal%@",date1];
                    share.date = date1;
                    [self.shareMgr insertWithShare:share];
                }
                
                
                NSString *date3 = [self.commentMgr getMinDateShareComment];
                if (!M_ISSTRNULL(date3)) {
                    
                } else {
                    date3 = curDate;
                    //        date3 = @"1456816235900";
                    EFengContent *comment = [[EFengContent alloc] init];
                    comment.isLocal = YES;
                    comment.shareId = [NSString stringWithFormat:@"isLocal%@",date3];
                    comment.date = date3;
                    [self.commentMgr insertWithShareComment:comment];
                }
                
                               
                [[CXmppRequestMgr shareInstance] getShareCommentListWithDate:date3 shareDate:date1 userId:self.curContact.UserID releaseUserId:@"" findType:@"down" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                    //         NSLog(@"3333");
                    
                    if ([responseObject[@"result"] isEqualToString:@"success"]) {
                        NSArray *array = responseObject[@"text"];
                        NSArray *commentArray = [EFengContent objectArrayWithKeyValuesArray:array];
                        [self.commentMgr batchInsertWithCommentList:commentArray];
                        [self.commentMgr batchUpdateUnreadCommentToReadCommentWithCommentList:commentArray];
                    }
                    [self handleComment];
                    
                } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                    [self handleComment];
                }];
                
                
                [[CXmppRequestMgr shareInstance] getShareListWithDate:date1 findType:@"down" userId:self.curContact.UserID releaseUserId:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                    
                    if ([responseObject[@"result"] isEqualToString:@"success"]) {
                        NSArray *array1 = responseObject[@"text"];
                        NSArray *shareArray = [EFengShare objectArrayWithKeyValuesArray:array1];
                        [self.shareMgr batchInsertWithShareList:shareArray];
                        [self.personMgr batchInsertWithShareList:shareArray];
                    }
                    
                    [self handleShareDataWithArray:[self.shareMgr getAttentionOlderShareWithMinTimeStamp:self.minAttentionShare.date curUserId:self.curContact.UserID]];
                } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                    [self handleShareDataWithArray:[self.shareMgr getAttentionOlderShareWithMinTimeStamp:self.minAttentionShare.date curUserId:self.curContact.UserID]];
                }];
            }
        }

        return;
    }
     NSArray *array = nil;
    if (self.maxShare == nil || self.minShare == nil) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView.footer endRefreshing];
            [self.tableView reloadData];
        });

    } else {
        array = [self.shareMgr getOlderShareWithMinTimeStamp:self.minShare.date];
        if (array.count > 0) {
            
            [self handleShareDataWithArray:array];
            
            } else {
                NSString *date1 = [self.shareMgr getMinDateShare];
                NSString *curDate = [UIUtil getCurrentTimeStamp];
                if (!M_ISSTRNULL(date1)) {
                    
                } else {
                    date1 = curDate;
                    //         date1 = @"1456816235900";
                    EFengShare *share = [[EFengShare alloc] init];
                    share.isLocal = YES;
                    share.shareId = [NSString stringWithFormat:@"isLocal%@",date1];
                    share.date = date1;
                    [self.shareMgr insertWithShare:share];
                }

                
                NSString *date3 = [self.commentMgr getMinDateShareComment];
                if (!M_ISSTRNULL(date3)) {
                    
                } else {
                    date3 = curDate;
                    //        date3 = @"1456816235900";
                    EFengContent *comment = [[EFengContent alloc] init];
                    comment.isLocal = YES;
                    comment.shareId = [NSString stringWithFormat:@"isLocal%@",date3];
                    comment.date = date3;
                    [self.commentMgr insertWithShareComment:comment];
                }
                
                [[CXmppRequestMgr shareInstance] getShareCommentListWithDate:date3 shareDate:date1 userId:self.curContact.UserID releaseUserId:@"" findType:@"down" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                    //         NSLog(@"3333");
                    
                    if ([responseObject[@"result"] isEqualToString:@"success"]) {
                        NSArray *array = responseObject[@"text"];
                        NSArray *commentArray = [EFengContent objectArrayWithKeyValuesArray:array];
                        [self.commentMgr batchInsertWithCommentList:commentArray];
                        [self.commentMgr batchUpdateUnreadCommentToReadCommentWithCommentList:commentArray];
                        
                    }
                    [self handleComment];
                    
                } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                    [self handleComment];
                }];

                
              [[CXmppRequestMgr shareInstance] getShareListWithDate:date1 findType:@"down" userId:self.curContact.UserID releaseUserId:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                  
                  if ([responseObject[@"result"] isEqualToString:@"success"]) {
                       NSArray *array1 = responseObject[@"text"];
                        NSArray *shareArray = [EFengShare objectArrayWithKeyValuesArray:array1];
                        [self.shareMgr batchInsertWithShareList:shareArray];
                        [self.personMgr batchInsertWithShareList:shareArray];
                    }
                  [self handleShareDataWithArray:[self.shareMgr getOlderShareWithMinTimeStamp:self.minShare.date]];
                  
                } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                    [self handleShareDataWithArray:[self.shareMgr getOlderShareWithMinTimeStamp:self.minShare.date]];
                }];
        }
    }
    
}

#pragma mark tableView代理以及数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
                return self.attentionDataArray.count;
    } else {
        
        return self.dataArray.count;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (self.allUnreadCommentCount > 0) {
        return 50.0f;
    } else {
       return 0.01f;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    if (self.allUnreadCommentCount > 0) {
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = WhiteColor;
        
        UIView *contentView = [[UIView alloc] init];
        contentView.layer.cornerRadius = 5.0f;
        contentView.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNewComment)];
        [contentView addGestureRecognizer:tap];
        contentView.backgroundColor = RGBACOLORWithAlpha(0, 0, 0, 0.7f);
        [view addSubview:contentView];
        
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(15.0f, 5.0f, 40.0f, 40.0f);
        imageView.layer.cornerRadius = 5.0f;
        imageView.layer.masksToBounds = YES;
        imageView.userInteractionEnabled = YES;
        [imageView sd_setImageWithURL:[NSURL URLWithString:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:self.lastUnReadComment.sendUserId]] placeholderImage:[UIImage imageNamed:@"80-80"]];
        [contentView addSubview:imageView];
        
//        NSString *string = [NSString stringWithFormat:@"%zd条新消息",self.allUnreadCommentCount];
        //bug 9476 fixed by lixu
        NSString *string ;
        if (self.allUnreadCommentCount > 99) {
            string = @"99+条新消息";
        }
        else
        {
            string = [NSString stringWithFormat:@"%zd条新消息",self.allUnreadCommentCount];
        }
        UILabel *label = [[UILabel alloc] init];
        label.font = Font15;
        label.text = string;
        label.textAlignment = UITextAlignmentLeft;
        label.textColor = WhiteColor;
        label.frame = CGRectMake(CGRectGetMaxX(imageView.frame) + 15.0f, 0, 100.0f, 50.0f);
        [contentView addSubview:label];
        
        CGFloat width = CGRectGetMaxX(label.frame) + 15.0f;
        contentView.frame = CGRectMake((HARDWARE_SCREEN_WIDTH - width) / 2.0f, 0, width, 50.0f);
        return view;
    } else {
        return nil;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EFengShareFrame *share = nil;
    if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
        share = self.attentionDataArray[indexPath.row];
    } else {
        share = self.dataArray[indexPath.row];
    }

    
    return share.cellHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EFengShareFrame *share = nil;
    if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
        share = self.attentionDataArray[indexPath.row];
    } else {
        share = self.dataArray[indexPath.row];
    }
    
    EFengShareCell *cell = [EFengShareCell eFengShaeCellWithTableView:tableView];
    cell.cellIndexPath = indexPath;
    cell.eFengShareCellDelegate = self;
    cell.shareFrame = share;
    
    return cell;
}

- (void)showNewComment
{
    EFengShareNewCommentController *new = [[EFengShareNewCommentController alloc] init];
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    nav.navigationBarHidden = NO;
    self.navigationController.navigationBarHidden = YES;

    [nav pushViewController:new animated:YES];
}
- (void)eFengShareCellDidClickHeadWithShare:(EFengShareFrame *)share indexPath:(NSIndexPath *)inedexPath
{
    [[EFengShareCommentToolBar defaultShareCommentToolBar] resetToolPositionToInitial];
    self.tabBarController.tabBar.hidden = NO;
    
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    nav.navigationBarHidden = NO;
    self.navigationController.navigationBarHidden = YES;
    
    EFengPersonalShareController *per = [[EFengPersonalShareController alloc] init];
    per.userId = share.share.releaseUserId;
    
    [nav pushViewController:per animated:YES];
}
//bug 9130 fix by lixu
- (void)eFengShareCellDidClickHuiFuWithShare:(EFengShareFrame *)share indexPath:(NSIndexPath *)inedexPath
{
    self.selectedShare = share.share;
    self.selectedComment = nil;
    EFengShareCommentToolBar *toolBar = [EFengShareCommentToolBar defaultShareCommentToolBar];
    if ([toolBar.contentText isFirstResponder] || !toolBar.isEmotionShow) {
        [toolBar resetToolPositionToInitial];
         self.tabBarController.tabBar.hidden = NO;
    } else {
        [toolBar.contentText becomeFirstResponder];
        toolBar.contentText.placeholder = @"回复...";
        self.tabBarController.tabBar.hidden = YES;
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:inedexPath];
        CGPoint pt = self.tableView.contentOffset;              
        CGFloat cellHeit = CGRectGetMaxY(cell.frame) - pt.y;
        if (cellHeit > toolBar.y) {
            
            
            pt.y = pt.y + cellHeit - toolBar.y;
            [self.tableView setContentOffset:pt animated:NO];
            
            
        } else {
           
            
        }
    }
    
}

- (void)eFengshareCommentsViewDidHuifuWithComment:(EFengContent *)comment share:(EFengShareFrame *)share indexPath:(NSIndexPath *)inedexPath
{
    
    self.selectedShare = share.share;
    self.selectedComment = comment;
    EFengShareCommentToolBar *toolBar = [EFengShareCommentToolBar defaultShareCommentToolBar];
        if ([comment.sendUserId isEqualToString:self.curContact.UserID]) {
        
            if ([toolBar.contentText isFirstResponder] || !toolBar.isEmotionShow) {
                [toolBar resetToolPositionToInitial];
                self.tabBarController.tabBar.hidden = NO;
            }

            
        RIButtonItem *cancelItem = [RIButtonItem itemWithLabel:@"取消" action:^{
            
        }];
        
        __block EFengShareController *block = self;
        
        RIButtonItem *selectItem = [RIButtonItem itemWithLabel:@"删除" action:^{
            [block.commentMgr updateShareCommentIsUnNetCompletedWithComment:comment isDel:YES];
            [[CXmppRequestMgr shareInstance] cancelPraiseShareWithCommentId:comment.commentId date:comment.date successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                
                if ([responseObject[@"result"] isEqualToString:@"success"]) {
                    
                    [block.commentMgr delShareCommentWithCommentId:comment.commentId];
                }
                
            } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                
            }];

            [self loadNewData];
        }];
        
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil cancelButtonItem:cancelItem destructiveButtonItem:nil otherButtonItems:selectItem, nil];
        [actionSheet showInView:self.view];

        
    } else {
        if ([toolBar.contentText isFirstResponder] || !toolBar.isEmotionShow) {
            [toolBar resetToolPositionToInitial];
            self.tabBarController.tabBar.hidden = NO;
        } else {
            [toolBar.contentText becomeFirstResponder];
            [toolBar.contentText setText:@""];
            [toolBar.contentText setPlaceholder:[NSString stringWithFormat:@"回复%@...",comment.sendUserName]];
            self.tabBarController.tabBar.hidden = YES;
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:inedexPath];
            CGPoint pt = self.tableView.contentOffset;
            CGFloat cellHeit = CGRectGetMaxY(cell.frame) - pt.y;
            if (cellHeit > toolBar.y) {
                pt.y = pt.y + cellHeit - toolBar.y;
                [self.tableView setContentOffset:pt animated:NO];
            }
        }
    }
    
}
- (void)eFengShareCellDidClickShanChuWithShare:(EFengShareFrame *)share indexPath:(NSIndexPath *)inedexPath
{
    if (![UIUtil isNetworkReachable]) {
        [MBProgressHUD showError:@"请检查网络设置"];
        return;
    }
    __block EFengShareController *block = self;
    JKAlertDialog *alert = [[JKAlertDialog alloc]initWithTitle:nil message:@"确定要删除该分享内容?"];
    [alert addButton:Button_OK withTitle:@"是" handler:^(JKAlertDialogItem *item) {
        [block.shareMgr delShareWithShareId:share.share.shareId];
//        [block.shareMgr updateShareIsUnNetCompletedWithShare:share.share isDel:YES];
        [block.personMgr delShareWithShareId:share.share.shareId];
        [[CXmppRequestMgr shareInstance] delShareWithDate:share.share.date shareId:share.share.shareId successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                [block.shareMgr delShareWithShareId:share.share.shareId];
            }
            
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];
        
        if ([block.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
            
            [block.attentionDataArray removeObject:share];
            [block.attentionShareDataArray removeObject:share.share];
        } else {
            [block.dataArray removeObject:share];
            [block.shareDataArray removeObject:share.share];
        }
        
        [block.tableView reloadData];

        
    }];
    
    [alert addButton:Button_CANCEL withTitle:@"否" handler:^(JKAlertDialogItem *item) {
        
        
    }];
    [alert show];

    
}
- (void)eFengShareCellDidClickZanWithShare:(EFengShareFrame *)share indexPath:(NSIndexPath *)inedexPath
{
    if (share.share.isZan) {
        EFengContent *comment = [self.commentMgr getZanIdWithShareId:share.share.shareId userId:self.curContact.UserID];
    
        [self.commentMgr updateShareCommentIsUnNetCompletedWithComment:comment isDel:YES];
        [[CXmppRequestMgr shareInstance] cancelPraiseShareWithCommentId:comment.commentId date:comment.date successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
                
                if ([responseObject[@"result"] isEqualToString:@"success"]) {
                    
                    [self.commentMgr delShareCommentWithCommentId:comment.commentId];
                }
                
            } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                
            }];

    } else {

        EFengContent *comment = [[EFengContent alloc] init];
        NSString *timeStamp = [UIUtil getCurrentTimeStamp];
        CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
        NSString *idkey = serverSetting.yuLiuZiduan1;
        if (M_ISSTRNULL(idkey)) {
            idkey = @"111111";
        }
        NSString *idStr = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
        
        comment.commentId = idStr;
        comment.shareId = share.share.shareId;
        comment.sendUserId = self.curContact.UserID;
        comment.yuLiuZiduan2 = 1;
        comment.sendUserName = self.curContact.UserName;
        comment.commentType = @"praise";
        comment.isClick = YES;
        comment.isRead = YES;
        comment.date = timeStamp;
        [self.commentMgr insertWithShareComment:comment];

        
        [[CXmppRequestMgr shareInstance] praiseShareWithSendUserId:self.curContact.UserID commentId:idStr releaseUserId:share.share.releaseUserId contentId:share.share.shareId sendUserName:self.curContact.UserName successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                [self.commentMgr updateCommentWithCommentId:[NSString stringWithFormat:@"%@",responseObject[@"id"]]
                 date:[NSString stringWithFormat:@"%@",responseObject[@"date"]]];
            }
           
            
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];

    }
   [self loadNewData];
}

- (void)sendMsg:(NSString *)txtMsg
{
    [[EFengShareCommentToolBar defaultShareCommentToolBar] resetToolPositionToInitial];
    self.tabBarController.tabBar.hidden = NO;
    if (M_ISSTRNULL(txtMsg)) {
        return;
    }
    NSString *type = nil;
    NSString *receiveUserId = nil;
    NSString *receiveUserName = nil;
    if (self.selectedComment) {
        type = @"reply";
        receiveUserId = self.selectedComment.sendUserId;
        receiveUserName = self.selectedComment.sendUserName;
    } else {
        type = @"comment";
    }
    
    EFengContent *content = [[EFengContent alloc] init];
    content.commentType = type;
    
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *idkey = serverSetting.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = @"111111";
    }
    NSString *idStr = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];

    content.commentId = idStr;

    content.sendUserId = self.curContact.UserID;
    content.sendUserName = self.curContact.UserName;
    content.shareId = self.selectedShare.shareId;
    
    content.receiveUserId = receiveUserId;
    content.receiveUserName = receiveUserName;
    content.content = txtMsg;
    content.isClick = YES;
    content.isRead = YES;
    content.yuLiuZiduan2 = 1;
    content.date = timeStamp;
    [self.commentMgr insertWithShareComment:content];
    [[CXmppRequestMgr shareInstance] composeShareCommentWithShareId:self.selectedShare.shareId commentId:idStr releaseUserId:self.selectedShare.releaseUserId sendUserId:self.curContact.UserID sendUserName:self.curContact.UserName receiveUserId:M_STOREVALUE(receiveUserId) receiveUserName:M_STOREVALUE(receiveUserName) content:txtMsg type:type successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"result"] isEqualToString:@"success"]) {
            [self.commentMgr updateCommentWithCommentId:[NSString stringWithFormat:@"%@",responseObject[@"id"]]
                                                        date:[NSString stringWithFormat:@"%@",responseObject[@"date"]]];
            [USER_DEFAULT setBool:YES forKey:@"sendOK"];
            [USER_DEFAULT synchronize];
        }

        
    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

    [self loadNewData];
}

- (void)eFengShareCellDidClickOpenWithShare:(EFengShareFrame *)share indexPath:(NSIndexPath *)inedexPath
{
    if ([self.settingModel.yuLiuZiduan1 isEqualToString:@"onlyAttention"]) {
        [self.attentionDataArray removeAllObjects];
        [self.attentionShareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
            
            if ([obj.shareId isEqualToString:share.share.shareId]) {
                obj.isOpen = !obj.isOpen;
            }
            
            EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
            
            obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
            obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
            obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
            if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                obj.isShowShanchu = YES;
            } else {
                obj.isShowShanchu = NO;
            }
            
            shareF.share = obj;
            [self.attentionDataArray addObject:shareF];
        }];

    } else {
        [self.dataArray removeAllObjects];
        [self.shareDataArray enumerateObjectsUsingBlock:^(EFengShare *obj, NSUInteger idx, BOOL *stop) {
            
            if ([obj.shareId isEqualToString:share.share.shareId]) {
                obj.isOpen = !obj.isOpen;
            }
            
            EFengShareFrame *shareF = [[EFengShareFrame alloc] init];
            
            obj.contentReply = [self.commentMgr getShareCommentWithShareId:obj.shareId];
            obj.isZan = [self.commentMgr isHasZanIdWithShareId:obj.shareId userId:self.curContact.UserID];
            obj.praiseArray = [self.commentMgr getSharePraiseWithShareId:obj.shareId];
            if ([self.curContact.UserID isEqualToString:obj.releaseUserId]) {
                obj.isShowShanchu = YES;
            } else {
                obj.isShowShanchu = NO;
            }
            
            shareF.share = obj;
            [self.dataArray addObject:shareF];
        }];
    }
    

    [self.tableView reloadData];

}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [[EFengShareCommentToolBar defaultShareCommentToolBar] resetToolPositionToInitial];
    self.tabBarController.tabBar.hidden = NO;
}
- (void)didTap:(UITapGestureRecognizer *)tap
{
    [[EFengShareCommentToolBar defaultShareCommentToolBar] resetToolPositionToInitial];
    self.tabBarController.tabBar.hidden = NO;
}
- (void)EFengShareCommentToolBarDidHiddenEmotionBtn
{
    [self.tabBarController.tabBar setHidden:NO];
}
//-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    if (tableView.isDragging && self.currentRow<indexPath.row) {
//        cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
//        [UIView animateWithDuration:1 animations:^{
//            cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
//
//        } completion:^(BOOL finished) {
//            if (finished) {
//                self.currentRow = indexPath.row;
//            }
//        }];
//    }
//}
@end
